check();
function check(){
    Ajax({
        url:"http://localhost/h5/php/check.php",
        success(res){
            const checkCode=document.getElementById("checkCode");
            checkCode.innerHTML=res
            console.log(res);
            sessionStorage.setItem("checkCode",res)
        }
    })
}
login()
function login(){
    const but = document.querySelector('.button')
    but.onclick = function(){
        const username = document.querySelector('.username').value;
        const password = document.querySelector('.password').value;
        const yzm = document.querySelector('.yzm').value;
        const checkCode = sessionStorage.getItem('checkCode');
        if(yzm.trim() != checkCode.trim()) return alert('验证码有误!')
        Ajax({
            url:"http://localhost/h5/php/login.php",
            data:{username,password},
            success(res){
                if(res.trim() === '账号密码有误'.trim()){
                    alert(res);
                }else{
                    sessionStorage.setItem('userinFo',res);
                    sessionStorage.setItem('login',1);
                    location.href = '../html/home.html';
                }
            }
        })
    }
}
